"""
工作流数据模型
"""
from datetime import datetime, timezone
from sqlalchemy import Column, Integer, String, Text, DateTime, Boolean
from database import Base


class Workflow(Base):
    """工作流表"""
    __tablename__ = "workflows"

    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    name = Column(String(255), nullable=False, index=True)
    description = Column(Text, nullable=True)
    workflow_definition = Column(Text, nullable=False)  # JSON 格式的工作流定义
    cron_expression = Column(String(100), nullable=True)
    cron_enabled = Column(Boolean, nullable=False, default=False)
    status = Column(String(50), nullable=False)  # 工作流状态
    created_at = Column(DateTime(timezone=True), nullable=False, default=lambda: datetime.now(timezone.utc))
    updated_at = Column(DateTime(timezone=True), nullable=False, default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc))
    deleted_at = Column(DateTime(timezone=True), nullable=True)
    created_by = Column(String(100), nullable=True)

    def __repr__(self):
        return f"<Workflow(id={self.id}, name='{self.name}', status='{self.status}')>"
